<!DOCTYPE html>
<html style="background: #f7f7f7;">
<head lang="en">
    <meta charset="UTF-8">
    <meta name='apple-touch-fullscreen' content='yes'>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta content="fullscreen=yes,preventMove=no" name="ML-Config">
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="format-detection" content="telephone=no,email=no,address=no"/>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>商品详情</title>
    <link rel="stylesheet" href="/style/wei/css/swiper.min.css">
    <link rel="stylesheet" href="/style/css/style1.css">
    <link rel="stylesheet" type="text/css" href="/style/css/sweet-alert.css"/>
    <script src="/style/js/index/style.js"></script>
    <script type="text/javascript" src="/style/wei/js/jquery.min.js"></script>
    <script src="/style/js/sweet-alert.min.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/style/new/js/jquery.lazyload.js"></script>
    <script type="text/javascript" src="/style/wei/js/jquery.cookies.js"></script>
    <style>

        .nostock{
            position: absolute;
            top: 0;
            z-index: 999;
            background: #fff;
            width: 2rem;
            height: 2rem;
            line-height: 2rem;
            color: #fff;
            border-radius: 2rem;
            background-color: rgba(235, 41, 148, 0.5)!important;
            filter: Alpha(opacity=50);
            background: #EB2994;
            text-align: center;
            font-size: .5rem;
            margin: 15% auto;
            right: 0;
            left: 0;
        }

        .d_count{ position: relative; }
        .d_count i{ position: absolute;top: -0.1rem;right: -0.10rem;background: #fc1d30;color: #fff;width: 0.4rem;font-size: 0.16rem;text-align: center;border-radius: 0.3rem;}
    </style>
</head>
<body>
<div id="loutinav">
    <a href="javascript:history.back(-1);" class="d_back"><img src="/style/images/index/d_2.png" alt=""></a>
    <ul>
        <li class="active"><span>商品</span> </li>
      <!--  <li><span>评价</span> </li>-->
        <li><span>详情</span> </li>
    </ul>
    <!--<a href="#" class="d_fx"><img src="/style/images/index/d_3.png" alt=""></a>-->
</div>
<div id="header">
    <div class="index_box jz640">
        <div class="detail_twoBox">
            <div class="detail_ban">
                <ul class="detail_two clearfix">
                    <?php
                    $default_share = '';
                   // $cnt = count($this->data['docids']);
                    if($this->data['docids'] && $this->data['docs']){
                    foreach($this->data['docids'] as $r){

                    if($default_share == "")
                    {
                        $default_share = $this->data['docs'][$r];
                    }
                    ?>
                    <li><a href='#'><img src="<?=$this->data['docs'][$r];?>" alt='ban2' ></a></li>
                    <?php
                        }
                    }
                    ?>
                </ul>
            </div>
            <ul class="num"></ul>
        </div>
    </div>
    <div class="header_top">
        <a href="javascript:history.back(-1);" class="d_back"><img src="/style/images/index/d_2.png" alt=""></a>
      <!--  <a href="#" class="d_fx"><img src="/style/images/index/d_3.png" alt=""></a>-->
    </div>
    <?php
    if($this->data['stock_number'] <1)
    {
        echo '<div class="nostock">补货中</div>';
    }
    ?>
</div>
<div id="main">
    <div class="louti">
        <div class="d_bk">
            <div class="d_blcontent">
                <h3>
                    <?php
                    if($this->data['shop_price']>0)
                    {
                        echo '<i>￥</i><em>'.$this->data['shop_price'].'</em>';
                    }
                    elseif($this->data['ximi_price'])
                    {
                        echo '<i></i><em>'.($this->data['ximi_price']*1).'硒米</em>';
                    }
                    ?>
                   

                </h3>
                <h4>￥<?=$this->data['market_price']?></h4>
            </div>
            <p><!--距结束<em>30:17:34</em>--></p>
            <!--<div class="d_nav">
            <img src="/style/images/index/d_5.png" alt="" class="d_v">
                <h3><i>开通掌柜 自购省</i><em>￥15.00</em><i>分享赚</i><em>￥15.00</em></h3>
                <a href="#"><i>去开通</i> <img src="images/d_6.png" alt=""></a>
            </div>-->
        </div>
        <div class="d_bar">
            <h4><?=$this->data['goods_name'];?></h4>
            <h5>累计热销<?=$this->data['sales_count'];?>件</h5>
        </div>
        <div class="d_by">
            <ul>
                <li>
                    <h3><i>已选</i><b>1件</b></h3>
                    <a href="#"><img src="images/d_7.png" alt=""></a>
                </li>
                <li>
                    <h3><i>配送</i><b></b></h3>
                    <a href="#"><em><?= $this->data['is_free_shipping']?"包邮":"8元";?></em><img src="images/d_7.png" alt=""></a>
                </li>
            </ul>
        </div>
    </div>
<!--    <div class="louti">
        <div class="d_pj">
            <dl>
                <dt>
                    <h3><span>商品评价</span><i>（5）</i></h3>
                    <a href="#"><i>查看全部</i><img src="images/d_8.png" alt=""></a>
                </dt>
                <dd>
                    <div class="d_top">
                        <img src="images/d_9.png" alt="" class="d_top_img">
                        <div class="d_top_right">
                            <h3>神秘用户</h3>
                            <h4>
                                <img src="images/d_10.png" alt="">
                                <img src="images/d_10.png" alt="">
                                <img src="images/d_10.png" alt="">
                                <img src="images/d_10.png" alt="">
                                <img src="images/d_10.png" alt="">
                            </h4>
                        </div>
                    </div>
                    <p>货真价实，挺好的</p>
                </dd>
                <dd>
                    <div class="d_top">
                        <img src="images/d_9.png" alt="" class="d_top_img">
                        <div class="d_top_right">
                            <h3>神秘用户</h3>
                            <h4>
                                <img src="images/d_10.png" alt="">
                                <img src="images/d_10.png" alt="">
                                <img src="images/d_10.png" alt="">
                                <img src="images/d_10.png" alt="">
                                <img src="images/d_10.png" alt="">
                            </h4>
                        </div>
                    </div>
                    <p>货真价实，挺好的</p>
                </dd>
            </dl>
        </div>
    </div>-->
    <div class="louti">
        <div class="d_xq">
            <div class="d_xq_left">
                <img src="<?=$this->data['supplier']['headimgurl'] !="" ?$this->data['supplier']['headimgurl']:'/style/images/index/d_9.png';?>" alt="">
                <i><?=$this->data['supplier']['supplier']?></i>
            </div>
            <a href="#" class="d_xq_right">
                进店逛逛
            </a>
        </div>
        <div>
            <?php
            $desc = htmlspecialchars_decode($this->data['goods_desc']);
            $desc = str_replace("<img src=","<img class=\"lazyimg\" src=\"/style/images/lazycover.jpg\" data-original=",$desc);
            echo $desc;
            ?>
        </div>
    </div>
</div>
<div class="d_footer">
    <ul class="d_footer_left">
        <li class="collection <?=$this->data['collection']>0?"d_on":'';?>"><a href="javascript:;"><img src="/style/images/index/d_<?=$this->data['collection']>0?15:11;?>.png" alt=""><span>收藏</span></a></li>
        <li><a href="#"><img src="/style/images/index/d_12.png" alt=""><span>客服</span></a></li>
        <li class="d_count"><a href="/cart/cart"><img src="/style/images/index/d_13.png" alt=""><span>购物车</span></a><i><?=$this->cartnum?></i></li>
    </ul>
    <div class="d_footer_right">
        <i onClick="_addtocart(<?php echo $this->data['goods_id']?>,0)">加入购物车</i>
        <span onClick="_addtocart(<?php echo $this->data['goods_id']?>,1)">立即购买</span>
    </div>
</div>

<script>
    var _added = false,
        _goodsid=<?=$this->data['goods_id']?>,
        _goods_number = <?= $this->data['stock_number']?:0;?>,
        _g_top = 0;
    $(function(){
        if(_goods_number < 1)
        {
            $(".d_footer_right").addClass("d_footer_on");
        }

        $(".lazyimg").lazyload({
            threshold : 150,
            placeholder : "/style/images/lazycover.jpg",
            failurelimit : 4
        });
        var detail_ban=$('.detail_two');
        var detail_ban_li=$('.detail_two li');
        var boxW=$(".detail_twoBox").width();

        var len=detail_ban_li.length+1;
        function startMove(){
            var i=0;
            var timer=null;
            detail_ban.css({width:len*boxW});//设置ban宽度
            detail_ban_li.css({width:100/len+"%"});//设置li宽度
            for (var j = 0; j < len-1; j++) {  //创建圆点
                $('.num').append('<li></li>')
            }
            $('.num li').first().addClass('active'); //给第一个圆点添加样式

            var firstimg=detail_ban_li.first().clone(); //复制第一张图片
            detail_ban.append(firstimg); //将第一张图片放到最后一张图片后，设置ul的宽度为图片张数*图片宽度
            //判断左右滑动切换
            detail_ban.on("touchstart", function(e) {
                //                            e.preventDefault();
                startX = e.originalEvent.changedTouches[0].pageX;
                //                            e.stopPropagation();
                return false;
            });
            detail_ban.on("touchend", function(e) {
                //                            e.preventDefault();
                //                            e.stopPropagation();
                moveEndX = e.originalEvent.changedTouches[0].pageX,
                    X = moveEndX - startX;
                if ( X > 0 ) {
                    clearInterval(timer);
                    i--;
                    if (i==-1) {
                        i=detail_ban_li.length-2;
                        detail_ban.css({left:-(len-1)*boxW});
                    }
                    detail_ban.stop().animate({left:-i*boxW},300);
                    $('.num li').eq(i).addClass('active').siblings().removeClass('active');
                }
                else if ( X < 0 ) {
                    clearInterval(timer);
                    i++;
                    if (i==len) {
                        i=1; //这里不是i=0
                        detail_ban.css({left:0}); //保证无缝轮播，设置left值
                    };
                    detail_ban.stop().animate({left:-i*boxW},300);
                    if (i==len-1) {   //设置小圆点指示
                        $('.num li').eq(0).addClass('active').siblings().removeClass('active');
                    }else{
                        $('.num li').eq(i).addClass('active').siblings().removeClass('active');
                    }
                }
                timer=setInterval(function(){
                    ss();
                },3000);
                return false;
            });
            //定时器自动播放
            timer=setInterval(function(){
                autoMove();
            },2500);
            function autoMove(){
                i++;
                if (i==len) {
                    i=1;
                    detail_ban.css({left:0});
                };
                detail_ban.stop().animate({left:-i*boxW},300);
                if (i==len-1) {
                    $('.num li').eq(0).addClass('active').siblings().removeClass('active');
                }else{
                    $('.num li').eq(i).addClass('active').siblings().removeClass('active');
                }
            }
        }
        //主要用于当调整浏览器窗口的大小时文档也相应调整
        $(window).resize(function() {
            boxW=$(".detail_twoBox").width();//获取改变后的窗口大小
            detail_ban.css({width:len*boxW});//设置ban外边框宽度
            detail_ban_li.css({width:100/len+"%"});//设置li宽度
        });
        startMove();//启动js
        //$(".cont img").removeAttr("height").removeAttr("width").css({"width":"100%","height":"auto"});
        //1.楼梯什么时候显示，800px scroll--->scrollTop
        $(window).on('scroll',function(){
            var $scroll=$(this).scrollTop();
            if($scroll>=100){
                $('#loutinav').show();
            }else{
                $('#loutinav').hide();
            }

            //4.拖动滚轮，对应的楼梯样式进行匹配
            $('.louti').each(function(){
                var $loutitop=$('.louti').eq($(this).index()).offset().top+100;
                //console.log($loutitop);
                if($loutitop>$scroll){//楼层的top大于滚动条的距离
                    $('#loutinav li').removeClass('active');
                    $('#loutinav li').eq($(this).index()).addClass('active');
                    return false;//中断循环
                }
            });
        });
        //2.获取每个楼梯的offset().top,点击楼梯让对应的内容模块移动到对应的位置  offset().left
        var $loutili=$('#loutinav li').not('.last');
        $loutili.on('click',function(){
            $(this).addClass('active').siblings('li').removeClass('active');
            var $loutitop=$('.louti').eq($(this).index()).offset().top;
            //获取每个楼梯的offsetTop值
            $('html,body').animate({//$('html,body')兼容问题body属于chrome
                scrollTop:$loutitop
            })
        });
        //3.回到顶部
        $('.last').on('click',function(){
            $('html,body').animate({//$('html,body')兼容问题body属于chrome
                scrollTop:0
            })
        });
    })

    // 收藏
    $(".collection").on("click",function(){


        $.post("/index/ajax",
            {
                "act":"collection",
                "goods_id":_goodsid,
                "mr":Math.random()
            },function(json){
                console.log(json);
                if(json.code==200)
                {
                    if(json.result ==1)
                    {
                        $(".collection img").attr("src","/style/images/index/d_15.png");
                        $(".collection" ).addClass("d_on");

                    }
                    else
                    {
                        $(".collection img").attr("src","/style/images/index/d_11.png");
                        $(".collection").removeClass("d_on");

                    }
                }
            },"json");

    });

    function _addtocart(goods_id,goto){
        //alert(goods_id)
        if(_goods_number > 0){
            $.post("/cart/cart_ajax",
                {
                    "goods_id":goods_id,
                    "goods_number":1,
                    "mr":Math.random()
                },
                function(json){
                    if(json.code == 200) {
                        _added = true;
                        if (goto == 1)
                        {
                            window.location.href = '/cart/cart';
                        }
                        else
                        {
                            swal('添加到购物车成功', false, "success");
                            if(json.cartnum>0)
                            {
                                if( $("#cartStatus span").hasClass("cartnum"))
                                {
                                    $("#cartStatus span").html(json.cartnum);
                                }
                                else
                                {
                                    $("#cartStatus img").before('<span class="cartnum">'+json.cartnum+'</span>')
                                }
                            }
                        }
                    }
                    else if(json.code==780) swal("商品补货中");
                    else if(json.code==781) swal("商品补货中");
                    else if(json.code==782) swal("已超过限购数量");
                    else if(json.code==783) swal("商品补货中");
                    else if(json.code==800) window.location.href = '/passport/signin';
                    else swal("加入购物车失败，请重试"+msg);

                },"json");
        }
    }
</script>

<?php
if($this->JSAPI){

    if($default_share == "")
    {
        $default_share = 'http://'.$_SERVER['HTTP_HOST'].'/style/wei/images/tuijian/tj_logo_big2.jpg';
    }
    ?>
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
    <script>
        wx.config({
            appId: '<?=$this->JSAPI['appId'];?>',
            timestamp: '<?=$this->JSAPI['timestamp'];?>',
            nonceStr: '<?=$this->JSAPI['nonceStr'];?>',
            signature: '<?=$this->JSAPI['signature'];?>',
            jsApiList: [
                'onMenuShareTimeline',
                'onMenuShareAppMessage'
            ]
        });
        wx.checkJsApi({
            jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage'],
            success: function(res) {
            }
        });
        wx.ready(function () {
            wx.onMenuShareAppMessage({
                title: '<?=$this->data['goods_name'];?> - 西海良品',
                desc: '绿色富硒、好吃不贵的优质农产品，自购省钱、分享返钱，欢迎加盟...',
                link: '<?=$this->JSAPI['url'];?>',
                imgUrl: '<?=$default_share;?>',
                type: 'link',
                dataUrl: '',
                success: function () {
                },
                cancel: function () {
                }
            });

            // 分享到朋友圈
            wx.onMenuShareTimeline({
                title: '<?=$this->data['goods_name'];?> - 西海良品',
                link: '<?=$this->JSAPI['url'];?>',
                imgUrl: '<?=$default_share;?>',
                success: function () {
                },
                cancel: function () {
                }
            });

        });
    </script>
    <?
}
?>
</body>
</html>